package com.lanou.bookstore.order.service;

import com.lanou.bookstore.order.dao.OrderDao;
import com.lanou.bookstore.order.domain.Order;
import com.lanou.bookstore.order.domain.OrderItem;

import java.sql.SQLException;
import java.util.List;

public class OrderService {
    private OrderDao orderDao = new OrderDao();

    public Integer addOrder(Order order) {
        Integer lastOid = null;
        try {
            lastOid = orderDao.addOrder(order);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return lastOid;
    }

    public void addOrderItem(OrderItem orderItem) {
        try {
            orderDao.addOrderItem(orderItem);
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

    public List<String> findOrderTimeByUid(String uid) {
        List<String> stringList = null;
        try {
            stringList = orderDao.findOrderTimeByUid(uid);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return stringList;
    }

    public List<Order> findOrderAllByOrderTime(String str) {
        List<Order> orderList = null;
        try {
            orderList = orderDao.findOrderAllByOrderTime(str);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return orderList;
    }

    public OrderItem findOrderItemAllByOid(Integer oid) {
        OrderItem orderItem = null;
        try {
            orderItem = orderDao.findOrderItemAllByOid(oid);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return orderItem;
    }

    public boolean findOrderStateByOid(Integer oid) {
        Integer result = null;
        try {
            result = orderDao.findOrderStateByOid(oid);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        if (result == 3) {
            return true;
        } else {
            return false;
        }
    }

    public void updateOrdersStateByOid(Integer oid) {
        try {
            orderDao.updateOrdersStateByOid(oid);
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

}
